mcmodhelpfandomcom-20200213-history
Crafting/Smelting Recipies
Crafting '''is the main method in which blocks and items are made in the game. There are two types of crafting in the game: the player's inventory, which contains a 2x2 crafting grid, and the Crafting Table, which contains a 3x3 crafting grid. Players move items from their inventory into the grid to form items and get an output of the newly crafted item. '''Smelting is the method used to get refined goods in the game. These goods can range from ores to cooked food, but the process remains the same. It can also be used to burn wooden items together to make charcoal, similar to coal. To smelt, one must insert a viable fuel source (i.e. coal, charcoal, lava, etc) on the bottom and the material to be smelted on the top. Once the item has finished smelting, the output will appear on the right. Overview First we will be handling crafting, then we will work on smelting: Crafting #Creating a shaped recipe #Creating a shapeless recipe Smelting # Creating a smelting recipe Crafting Shaped Recipes Shaped recipes are recipes that must have their items placed in a specific layout in order to yield an output (i.e. pickaxe, TNT, etc.). You will need to define the layout of your items with symbols in the code in order to create one. Go to your init method inside your ModClass and register a new recipe like so: GameRegistry.addRecipe(new ItemStack(), new Object[]{"", "", "",}); I've set this up this way so that I can easily demonstrate how the system works, but by default this would all be one line. Each quotation mark represents a row of the crafting table. To add an item to your recipe, simply add a variable to define which object you want. For example I'm going to make a recipe that takes in any kind of planks in a 'T' shape. GameRegistry.addRecipe(new ItemStack(modItems.test_item), new Object[]{"PPP", " P ", " P ",'P', Blocks.planks}); Notice how the "P" variable is surrounded by apostrophes and the empty spaces plus the varibles make up the 3x3 grid of the crafting table. You can fill these spaces with more materials and define said materials just like the last example, except you add the other materials in sequence after the first like so: GameRegistry.addRecipe(new ItemStack(modItems.test_item), new Object[]{"PPP", "GPG", "GPG",'P', Items.planks, 'G', Blocks.gold_ingot}); You can add as many of these items as you can fit on the table by just continuing this pattern. You can also make this method compatible with the player's crafting interface by simply taking away one row and column and repeating the same process. Shapeless Recipes Shapeless recipes do not need the required items placed in any sort of layout, making them quick and easy to craft. A common example of a shapeless recipe would be that of flint and steel, since you can place the flint and iron anywhere on the grid and still get a flint and steel item. To create a shapeless recipe, write this line of code in the init method of your ModClass: GameRegistry.addShapelessRecipe(newItemStack(modItems.test_item), new Object[]{Items.redstone, new ItemStack(Items.dye, 1, 4)}) The first argument in the method defines the output of the recipe, as per usual. The object array defines all of the blocks, items, and itemStacks needed in the recipe. This specific recipe takes in a lapis lazuli item and a redstone item, and returns a test_item. This is the perfect opportunity to talk about itemStacks. The new itemStack we created for this recipe declares a new Item object (an instance of the Item class) and specifies the 'dye' item within the class. This 'dye' item is what we call a "metadata-sensitive item." We will talk about metadata objects in a later tutorial, but for now all you need to know is that the 'dye' item has several different variants, all of the dyes in the game, so we need to specify which variant to use. The itemStack here defines one item of the type dye with a metadata of 4, which is lapis lazuli. Smelting Recipes When creating smelting recipes, it is relatively straightforward, because we only need an input and an output. Like before, write this code in the init method of your ModClass: GameRegistry.addSmeltingGameRegistry.addSmelting(Items.diamond, new ItemStack(ModItems.tutorialItem), 1.0F); As you can see, this is very similar to the previous registries, except that this recipe only needs an input and an output. The input, the first argument (in this case, diamond), can be a single item, block, or an itemStack. However the output, the second argument (in this case, tutorialItem), must be an itemStack. The final argument defines the amount of experience that the player receives after taking the output from the furnace. Here is a table of the most common values and their items: You should now be able to use these registers to create your own recipes so you can get them in survival mode, happy modding!